$(function(){
    function pagination(type,totalPage){
        $('.pagination').pagination(totalPage,{
            num_edge_entries: 2, //边缘页数
            num_display_entries: 4, //主体页数
            items_per_page: 1, //每页显示1项
            prev_text:"上一页",
            next_text:"下一页",
            callback: function(currentPage){
                list(type,currentPage+1,false)
            }
        })
    }
    function list(type,currentPage,initPage){
        $.ajax({
            url: '/flowing/list',
            data:{
                keyWord: type,
                pageStart: currentPage,
                pageSize: 10
            },
            type: 'get',
            typeDate: 'json',
            success: function(data){
                if(data.success){
                    if(data.count==0){
                        $('.accountFlowing ul').empty().html('<p style="padding-top: 50px; text-align: center; color: #999;">暂无数据</p>');
                    }else{
                        var pages = Math.ceil(data.count/10);
                        if(pages>1){
                            if(initPage){
                                pagination(type,pages);
                                $('#Pagination').show();
                            }
                        }else{
                            $('#Pagination').hide();
                        }
                        var listHtml='';
                        var isEven = '';
                        for(i=0;i<data.financieraccountflowlist.length;i++){
                            if(i%2==1){
                                isEven = 'even'
                            }else{
                                isEven = ''
                            }
                            listHtml += '<li class="'+isEven+'">' +
                                '                    <span>'+data.financieraccountflowlist[i].id+'</span>' +
                                '                    <span>'+data.financieraccountflowlist[i].transName+'</span>' +
                                '                    <span>'+data.financieraccountflowlist[i].amount.toFixed(2)+'</span>' +
                                '                    <span>'+data.financieraccountflowlist[i].subTransCodeName+'</span>' +
                                '                    <span>'+data.financieraccountflowlist[i].addTime+'</span>' +
                                '                </li>'
                        }
                        $('.accountFlowing ul').empty().append(listHtml);
                    }

                }else{
                    $('.accountFlowing ul').empty().html('<p style="padding-top: 50px; text-align: center; color: #999;">'+data.msg+'</p>');
                }
            },
            error: function(){}
        })
    }
    list(0,1,true);
    //tab
    $('.accountPos li:eq(0)').addClass('on');
    $('.accountPos li').on('click',function(){
        var index = $(this).index();
        $(this).addClass('on').siblings().removeClass('on');
        list(index,1,true);
    });
});